# encoding=utf8
import json
import re
import math
import codecs
from pymongo import MongoClient
from bson import json_util
from urllib.parse import quote_plus
from tqdm import tqdm

user = 'mongouser'
pwd = 'tuanjie123'
host = '118.25.106.14'
port = 27017
url = 'mongodb://%s:%s@%s' % (quote_plus(user), quote_plus(pwd), host)

client = MongoClient(url, port=port)
collection_task_test = client['tagging_test']['task_test']
collection_content = client['tagging_test']['content']
# 分类
# lines = list(collection.aggregate([
#     {
#         '$lookup': {'from': "content", 'localField': "newsId", 'foreignField': "newsId", 'as': "haah"}
#     }
# ]))
lines = collection_task_test.find(
    {
        'taskKey': 'MultiDocSum2',
        'canOutput': 1
    },
    {
        # 'checkData': 1,
        # 'reCheckData': 1,
        # 'finalData': 1,
        # 'checkDate': 1,
        # 'newsId': 1,
        '_id': 0
    },
    no_cursor_timeout=True
)

print(lines.count())

save_data = []
for line in tqdm(lines, total=lines.count()):
    save_data.append(line)

json.dump(save_data, codecs.open('./MultiDoc_json_file/file1.json', 'w', encoding='utf-8'), ensure_ascii=False, indent=4)
